package com.gsta.cdn.cdr.controller;

import com.gsta.cdn.cdr.entity.ResultEntity;
import com.gsta.cdn.cdr.mapper.FileSizeMapper;
import com.gsta.cdn.cdr.mapper.HotSimilarMapper;
import com.gsta.cdn.cdr.service.FileSizeService;
import com.gsta.cdn.cdr.service.HotSimilarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(path = "/HotSimilar")
public class HotSimilarController {
    @Autowired
    private HotSimilarMapper hotSimilarMapper;

    @Resource
    private HotSimilarService hotSimilarService;

    //三级节点相似度统计
    @RequestMapping(path = "/HotSimilar", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity FileSizeAll(@RequestParam(required = true) String date,
                                    @RequestParam(required = true) String percent,
                                    @RequestParam(required = false,defaultValue = "1")int page,
                                    @RequestParam(required = false,defaultValue = "200")int pageSize,
                                    HttpServletResponse response) {

        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Cache-Control","no-cache");
        List<Map<String, Object>> list = hotSimilarService.HotSimilar(date,percent,page,pageSize);
        int total = hotSimilarMapper.HotSimilarCount(date,percent);
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setCount(total);
            resultEntity.setData(list);
            if (list.size() > 0){
                resultEntity.setMsg("查询成功");
                resultEntity.setCode(0);
            }else{
                resultEntity.setMsg("无数据");
                resultEntity.setCode(-1);
            }
            return resultEntity;
        }
        catch (Exception e){
            return ResultEntity.error("查询失败");
        }
    }
}
